package com.itheima.test2;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Test {
    public static void main(String[] args) throws ParseException {
        String s="2020-11-11 12:13:14";
        StringToDate(s);//字符串转化为Date对象
        DateToString();// Date对象转化为字符串
    }

    private static void DateToString() {// Date对象转化为字符串
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String day = format.format(date);
        System.out.println("转化的字符串对象为"+day);
    }

    private static void StringToDate(String s) throws ParseException {//字符串转化为Date对象
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = format.parse(s);
        System.out.println("转化的Date对象为:"+date);
    }
}
